package com.xframe.xdal.core.serialize;

import com.xframe.xdal.core.constant.MappingConstants;
import com.xframe.xdal.core.model.IJsonModel;
import com.xframe.xdal.core.serialize.proc.ISerializeProc;
import com.xframe.xdal.core.serialize.proc.SerializeProcFactory;
import com.xframe.xdal.core.util.StringUtil;
import lombok.Data;
import lombok.ToString;

/**
 * @Author: GZC
 * @createTime: 2023年05月23日
 * @Description:
 */
@Data
@ToString
public class JsonModel implements IJsonModel {
    /**
     * 字段名
     */
    private String name;
    /**
     * 映射字段
     */
    private String mapName;
    /**
     * 关联对象
     */
    private String refModelCode;
    /**
     * 关联类型
     */
    private String refModelType;
    /**
     * 标记
     */
    private String flag;
    /**
     * 处理类
     */
    private String procClass;
    /**
     * 参数
     */
    private String classArgs;
    /**
     * 导出的列头名称
     */
    private String header;


    @Override
    public boolean isRefModel(){
        return StringUtil.isNotEmpty(refModelCode) && StringUtil.isNotEmpty(refModelType);
    }

    @Override
    public boolean isRefObj(){
        return refModelType.equals(MappingConstants.MAPPING_REF_OBJ);
    }

    @Override
    public boolean isRefArray(){
        return refModelType.equals(MappingConstants.MAPPING_REF_ARR);
    }

    @Override
    public boolean hasSerializeProc(){
        return StringUtil.isNotEmpty(this.procClass);
    }

    @Override
    public ISerializeProc getSerializeProc(){
        try {
            return SerializeProcFactory.build(this.procClass,this.classArgs);
        }catch (Exception ex){
            return null;
        }
    }
}
